//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbChucVu
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_SelectAll1", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbChucVu OTbChucVu)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenChucVu", OTbChucVu.TenChucVu);
            pr[1] = new SqlParameter(@"TrangThai", OTbChucVu.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbChucVu_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbChucVu OTbChucVu)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaChucVu", OTbChucVu.MaChucVu);
            pr[1] = new SqlParameter(@"TenChucVu", OTbChucVu.TenChucVu);
            pr[2] = new SqlParameter(@"TrangThai", OTbChucVu.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbChucVu_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaChucVu)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaChucVu",MaChucVu);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbChucVu_Delete", pr);
        }
        //-----------------------------------------------------------//

        public static bool KiemTraDuLieu_Sua(ETbChucVu ChucVu)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenChucVu", ChucVu.TenChucVu);
            pr[1] = new SqlParameter(@"MaChucVu", ChucVu.MaChucVu);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//

        public static bool KiemTraDuLieu(ETbChucVu ChucVu)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenChucVu", ChucVu.TenChucVu);
     
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static DataTable SearchChucVu(ETbChucVu ChucVu)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenChucVu", ChucVu.TenChucVu);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbChucVu_Search", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static ETbChucVu SelectByID(int MaChucVu)
        {
            ETbChucVu OTbChucVu = new ETbChucVu();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaChucVu",MaChucVu);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbChucVu_SelectByID", pr);
            if (idr.Read())
              OTbChucVu = GetOneTbChucVu(idr);
            idr.Close();
            idr.Dispose();
            return OTbChucVu;
        }
//-----------------------------------------------------------//
        private static ETbChucVu GetOneTbChucVu(IDataReader idr)
       {
            ETbChucVu OTbChucVu = new ETbChucVu();
                if (idr["MaChucVu"] != DBNull.Value)
                    OTbChucVu.MaChucVu = (int)idr["MaChucVu"];
                if (idr["TenChucVu"] != DBNull.Value)
                    OTbChucVu.TenChucVu = (string)idr["TenChucVu"];
                if (idr["TrangThai"] != DBNull.Value)
                    OTbChucVu.TrangThai = (int)idr["TrangThai"];
            return OTbChucVu;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaChucVu)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaChucVu",MaChucVu);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbChucVu_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbChucVu> ListAll()
        {
            List<ETbChucVu> list = new List<ETbChucVu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbChucVu_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbChucVu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbChucVu> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbChucVu> list = new List<ETbChucVu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbChucVu_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbChucVu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}